#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <sys/types.h>          /* See NOTES */
#include <sys/socket.h>
#include <netinet/in.h>
#include <strings.h>
#include <string.h>
//#include <error.h>


int main(int argc, char **argv) 
{
    int socknd, sockacc;
    struct sockaddr_in servx;
    struct sockaddr_in clix;
    char buf[255];
    char *ww;
    int rt;
    int n;
    size_t cli_len;

    bzero(buf, 255);
    bzero(&servx, sizeof(servx));
    socknd = socket(AF_INET, SOCK_STREAM, 0); 

    servx.sin_family = AF_INET;
    servx.sin_port = htons(181);
    servx.sin_addr.s_addr = INADDR_ANY;

    //inet_pton(AF_INET, "127.0.0.1", &servx.sin_addr);

    rt = bind(socknd, (struct sockaddr *)&servx, sizeof(servx));
    printf("rt: %d \r\n", rt);
    //rt = errno();
    if(rt < 0) {
    printf("s: %s \r\n", strerror(errno));
    exit(1);
    }

    bzero(buf, 255);
    rt = listen(socknd, 5);
    cli_len = sizeof(clix);
    sockacc = accept(socknd, (struct sockaddr *)&clix, &cli_len);
    if(sockacc < 0) {
    printf("s: %s \r\n", strerror(errno));
    exit(1);
    }

    n = read(sockacc, buf, 254);  

    printf("s buf: %d  %s \r\n", n, buf);
    write(sockacc, buf, 254);

    printf("s buf: %s \r\n", buf);

    close(socknd);

    return 0;
}
